home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-07 | 1.1 KB | 40 lines | [TEXT/ttxt] |
- // htmlcopy.lib - Useful routine for CMMCGI.EXE to copy from an existing html
- // ver.1 file and make changes to it.
- //
- // *** ReadFile() - Read file into a buffer
- // SYNTAX: buf ReadFile(FileSpec)
- // WHERE: FileSpec: specification for file, probably an HTML file
- // RETURN: return string as read from file, or NULL if failed
- //
- // *** StrReplace()- String Replace
- // SYNTAX: bool StrReplace(Str,Find,Replace)
- // WHERE: Str: String to search in
- // Find: string to search for (case-sensitive)
- // Replace: string to replace it with
- // RETURN: Pointer beyond string if found and replaced, else NULL
- //
- //
-
- ReadFile(pFileSpec)
- {
- if ( !(fp = fopen(pFileSpec,"rb")) )
- return NULL;
- lTotalLen = 0;
- lBuf = "";
- while ( 0 < (lLen=fread(lBuf+lTotalLen,20000,fp)) )
- lTotalLen += lLen;
- fclose(fp);
- SetArraySpan(lBuf,lTotalLen); // don't waste space
- return lBuf;
- }
-
- StrReplace(pStr,pFind,pReplace)
- {
- if ( !(lFind = strstr(pStr,pFind)) )
- return NULL;
- lRepLen = strlen(pReplace);
- strcpy(lRet=lFind+lRepLen,lFind+strlen(pFind));
- memcpy(lFind,pReplace,lRepLen);
- return lRet;
- }
-